package com.hailian.fintech.hlhouse_statusserver.web;


import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.hailian.fintech.hlhouse_statusserver.entity.*;
import com.hailian.fintech.hlhouse_statusserver.service.*;
import com.hailian.fintech.hlhouse_statusserver.vo.ResultEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author hanbo
 * @since 2020-06-01
 */
@RestController
@RequestMapping("/housing")
public class HousingController {

    //注入房源service
    @Autowired
    private IHousingService iHousingService;

    //注入楼盘service
    @Autowired
    private IBuildingService iBuildingService;

    //注入租房状态service
    @Autowired
    private IRentsService iRentsService;

    //注入管家service
    @Autowired
    private IStewardService iStewardService;

    //注入状态service
    @Autowired
    private IStateService iStateService;

    //注入房源类型service
    @Autowired
    private ITypeService iTypeService;

    /**
     * 查询所有房源信息
     * @return
     */
    @RequestMapping("/findAllByHouseList")
    public ResultEntity findAllByHouseList(Integer stid,String bName){
        //查询所有房源信息
        List<Housing> HouseList = iHousingService.findAllByHouseList(stid,bName);

        //关联查询楼盘名称
        for(Housing houslist:HouseList){
            Building building = iBuildingService.selectById(houslist.getBid());
            houslist.setBName(building.getName());
        }
        //关联查询租房状态名称
        for(Housing houslist:HouseList){
            Rents rents = iRentsService.selectById(houslist.getHouseRentId());
            houslist.setHouseRentName(rents.getName());
        }
        //关联查询房源类型名称
        for(Housing houslist:HouseList){
            Type type = iTypeService.selectById(houslist.getHouseTypeId());
            houslist.setHouseTypeName(type.getName());
        }
        //关联查询管家名称
        for(Housing houslist:HouseList){
            Steward steward = iStewardService.selectById(houslist.getSid());
            houslist.setSName(steward.getName());
        }
        //关联查询状态名称
        for(Housing houslist:HouseList){
            State state = iStateService.selectById(houslist.getStid());
            houslist.setStName(state.getName());
        }
        return ResultEntity.ok(HouseList);
    }

    /**
     * 新增房源（分散式 集中式）
     * @param housing
     * @return
     */
   /* @RequestMapping("Inserthouse")
    public ResultEntity Inserthouse(@RequestBody Housing housing){
        iHousingService.insert(housing);
        return ResultEntity.ok(true);
    }*/

}
